import {createRouter, createWebHashHistory} from 'vue-router'

import Login from "../components/login/Login.vue"
import Home from "../components/home/Home.vue"
import Welcome from "../components/home/Welcome.vue"
import AccountList from "../components/home/admin/account/List.vue"
import DictList from "../components/home/admin/dict/List.vue"
import LogList from "../components/home/admin/log/List.vue"
import OrgHome from "../components/home/admin/org/Home.vue"
import Demo from "../components/home/admin/Demo.vue"


import Store from './Storage'

const Router = createRouter({
    history: createWebHashHistory(),
    routes:[{
        path : '/login',
        component:Login,
        name: 'login'
    },{
        path : '/home',
        component:Home,
        name: 'home',
        children:[{
            path : '/welcome',
            component:Welcome,
            name: 'welcome'
        },{
            path : '/admin/account',
            component: AccountList,
            name : 'accountList'
        },{
            path : '/admin/org',
            component: OrgHome,
            name : 'orgTree'
        },{
            path : '/admin/dict',
            component: DictList,
            name : 'dictList'
        },{
            path : '/admin/log',
            component: LogList,
            name : 'logList'
        },{
            path : '/admin/schedule',
            component: Demo,
            name : 'demo'
        }]
    }]
})

Router.beforeEach((from)=>{
    let isLogin = Store.getters.isLogin
    if(isLogin || from.name == 'login'){
        return true
    }else{
        return{ name : 'login'}
    }
})
export default Router